using System;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
  [TestFixture]
  public class RequiredGuidRuleAttributeTest
  {
    [Test]
    public void CheckDefaultValues()
    {
      var ruleAttribute = new RequiredGuidRuleAttribute();
      Assert.AreEqual(null, ruleAttribute.InitialValue);

	  var propertyRule = (RequiredRule<Guid>)ruleAttribute.CreateInstance(new MockPropertyDescriptor<Guid>("foo"));
	  var parameterRule = (RequiredRule<Guid>)ruleAttribute.CreateInstance(new MockParameterDescriptor<Guid>("foo"));
	  var fieldRule = (RequiredRule<Guid>)ruleAttribute.CreateInstance(new MockFieldDescriptor<Guid>("foo"));

    }

    [Test]
    public void CheckNonDefaultValues()
    { 
      const string expectedInitialValueString = "11111111-1111-1111-1111-111111111111";
      var expectedInitialValueGuid = new Guid(expectedInitialValueString);
      var ruleAttribute = new RequiredGuidRuleAttribute
                                                    {InitialValue = expectedInitialValueString};
        Assert.AreEqual(expectedInitialValueString, ruleAttribute.InitialValue);

      var propertyRule = (RequiredRule<Guid>)ruleAttribute.CreateInstance(new MockPropertyDescriptor<Guid>("foo"));
      var parameterRule = (RequiredRule<Guid>)ruleAttribute.CreateInstance(new MockParameterDescriptor<Guid>("foo"));
	  var fieldRule = (RequiredRule<Guid>)ruleAttribute.CreateInstance(new MockFieldDescriptor<Guid>("foo"));

      Assert.AreEqual(expectedInitialValueGuid, propertyRule.InitialValue);

      Assert.AreEqual(expectedInitialValueGuid, parameterRule.InitialValue);

	  Assert.AreEqual(expectedInitialValueGuid, fieldRule.InitialValue);
    }




      [Test]
      public void CallAttributeTester()
      {
          AttributeTester.CheckDefaultValues<Guid>(new RequiredGuidRuleAttribute(), true, true, true);
          AttributeTester.CheckNonDefaultValues<Guid>(new RequiredGuidRuleAttribute(), true, true, true);
      }
  }
}